package org.statewalker.core;

public class PrintState extends AsyncState {

    public final static IStateFactory FACTORY = new IStateFactory() {
        public IState newState(String stateKey) {
            return new PrintState();
        }
    };

    @Override
    protected void doActivate(IEvent event, ICallback callback)
        throws Exception {
        println(fKey + ": activation " + Thread.currentThread());
        callback.finish(event);
    }

    @Override
    protected void doDeactivate(IEvent event, ICallback callback)
        throws Exception {
        println(fKey + ": deactivation " + Thread.currentThread());
        callback.finish(event);
    }

    @Override
    protected void doOnTransition(IState prev, IEvent event, IState next) {
        println(prev + " =" + event + "=> " + next);
    }

    protected void println(String string) {
        IState state = this;
        while (state != null) {
            System.out.print("    ");
            state = state.getParent();
        }
        System.out.println(string);
    }
}
